package com.demo2do.fms.entity.appraisal;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.demo2do.core.format.PersistentFormat;
import com.demo2do.fms.entity.authority.Branch;
import com.demo2do.fms.entity.supplier.common.Supplier;

/**
 * 绩效考核模板
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "FMS_APPRAISAL_TEMPLATE")
@PersistentFormat
public class AppraisalTemplate {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 考核名称 */
    private String name;
    
    /** 考核供方类别 */
    @Enumerated(EnumType.STRING)
    private AppraisalTarget target;
    
    /** 是否是总部创建 */
    @Column(name = "is_admin_create")
    private boolean adminCreate;
    
    /** 创建人所属分区 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "branch_id", referencedColumnName = "id")
    private Branch branch;
    
    /** 创建人所属供方 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    private Supplier supplier;
    
    /** 创建人 */
    private Long creator;

    /** 创建时间 */
    private Date createTime;

    /** 最后修改人 */
    private Long lastOperator;

    /** 最近修改时间 */
    private Date lastModifyTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public AppraisalTemplate() {
    }
    
    /**
     * @param adminCreate
     * @param creator
     * @return
     */
    public AppraisalTemplate initialize(boolean adminCreate, Long creator) {
        this.adminCreate = true;
        this.creator = creator;
        this.createTime = new Date();
        this.lastOperator = creator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @param branch
     * @param creator
     * @return
     */
    public AppraisalTemplate initialize(Branch branch, Long creator) {
        this.branch = branch;
        this.adminCreate = false;
        this.creator = creator;
        this.createTime = new Date();
        this.lastOperator = creator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @param supplier
     * @param creator
     * @return
     */
    public AppraisalTemplate initialize(Supplier supplier, Long creator) {
        this.supplier = supplier;
        this.adminCreate = false;
        this.creator = creator;
        this.createTime = new Date();
        this.lastOperator = creator;
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * @param template
     * @param operator
     * @return
     */
    public AppraisalTemplate edit(AppraisalTemplate template, Long operator) {
        this.name = template.getName();
        this.target = template.getTarget();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @param operator
     * @return
     */
    public AppraisalTemplate delete(Long operator) {
        this.disabled = true;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the target
     */
    public AppraisalTarget getTarget() {
        return target;
    }

    /**
     * @return the adminCreate
     */
    public boolean isAdminCreate() {
        return adminCreate;
    }

    /**
     * @return the branch
     */
    public Branch getBranch() {
        return branch;
    }

    /**
     * @return the supplier
     */
    public Supplier getSupplier() {
        return supplier;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastOperator
     */
    public Long getLastOperator() {
        return lastOperator;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param target the target to set
     */
    public void setTarget(AppraisalTarget target) {
        this.target = target;
    }

    /**
     * @param adminCreate the adminCreate to set
     */
    public void setAdminCreate(boolean adminCreate) {
        this.adminCreate = adminCreate;
    }

    /**
     * @param branch the branch to set
     */
    public void setBranch(Branch branch) {
        this.branch = branch;
    }

    /**
     * @param supplier the supplier to set
     */
    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastOperator the lastOperator to set
     */
    public void setLastOperator(Long lastOperator) {
        this.lastOperator = lastOperator;
    }

    /**
     * @param lastModifyTime the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
}